Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target_version to formatter options #9220

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Dec 21, 2023

Summary

This PR adds the target_version option to the formatter option and initializes it with the target_version specified in the ruff.toml.

The new configuration doesn't yet affect any formatting.

Test Plan

I ran ruff manually in my test project and added a dbg statement to to_format_options. Changes to target-version in the configuration were reflected in the debug printed PyFormatOptions. Verified that using requires-python works as intended.

@MichaReiser MichaReiser added configuration Related to settings and configuration formatter Related to the formatter labels Dec 21, 2023
Comment on lines 368 to 383
#[derive(CacheKey, Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Default)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "lowercase")
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum PythonVersion {
Py37,
#[default]
Py38,
Py39,
Py310,
Py311,
Py312,
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could have a single PythonVersion definitions shared by the linter and formatter but there's currently no good crate where to place it. Creating one feels overkill for such a simple definition.

Ultimately I think the definition should be in ruff_python_ast where it specifies the language features.

@MichaReiser MichaReiser force-pushed the add-target-version-to-formatter-options branch from 6bc4c0f to 37ddbea Compare December 21, 2023 02:51
Copy link
Contributor

github-actions bot commented Dec 21, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser enabled auto-merge (squash) December 21, 2023 04:02
@MichaReiser MichaReiser merged commit 8cb7950 into main Dec 21, 2023
16 checks passed
@MichaReiser MichaReiser deleted the add-target-version-to-formatter-options branch December 21, 2023 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants